interface Prop {
  [key: string]: any;
}
export const filterObj = (newObj: Prop, oldObj: Prop, idKey?: string) => {
  const result: Prop = {};
  // eslint-disable-next-line no-param-reassign
  if (!idKey) idKey = 'id';
  if (Object.is(newObj, oldObj)) {
    return undefined;
  }
  if (!oldObj || typeof oldObj !== 'object') {
    return oldObj;
  }
  Object.keys(newObj || {})
    .concat(Object.keys(oldObj || {}))
    .forEach(key => {
      if (oldObj[key] !== newObj[key] && !Object.is(newObj[key], oldObj[key])) {
        if (typeof newObj[key] !== 'object') {
          result[key] = newObj[key];
        }
      }
    });
  result[idKey] = newObj[idKey];
  return result;
};
